// Problem: 
// Contest: 
// URL: 
// Memory Limit: 
// Time Limit: 
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,a,n) for(int (i)=(a);(i)<=(n);(i)++)
#define pre(i,a,n) for(int (i)=(a);(i)>=(n);(i)--)
//const int N,mod;
inline int read(){
	int s=0,w=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
	while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
	return s*w;
}
void solve()
{
	string s;
	cin>>s;
	int m=s.size();
	int n;
	cin>>n;
	string a,b;
	cin>>a>>b;
	int i=0,j=0;
	while(j!=n)
	{
		if(i>=m)
		{
			cout<<"YES"<<endl;
			return;
		}
		int tmp=i,t=i;
		for(char k=a[j];k<=b[j];k++)
		{
			tmp=i;
			while(tmp<=m-1&&s[tmp]!=k)
			{
				if(tmp==m-1)
				{
					cout<<"YES"<<endl;
					return;
				}
				tmp++;
			}
			t=max(t,tmp);
		}
		i=t+1;
		j++;
	}
	cout<<"NO"<<endl;
}
signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	int T=1;
	cin>>T;
	while(T--)
	{
		solve();
	}
	return 0;
}
